package com.jrx.anytxn.param.service.billCompare.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.param.constant.Constant;
import com.jrx.anytxn.param.dto.billCompare.TlThirdBillDetailRes;
import com.jrx.anytxn.param.entity.TlBillTransCompareDetail;
import com.jrx.anytxn.param.entity.TlThirdBillDetail;
import com.jrx.anytxn.param.mapper.ext.ExtTlBillTransCompareDetailMapper;
import com.jrx.anytxn.param.mapper.ext.ExtTlThirdBillDetailMapper;
import com.jrx.anytxn.param.service.billCompare.ITlThirdBillDetailService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @Author llk
 * @Date 3:02 下午 星期六 2021/7/17
 **/
@Service
public class TlThirdBillDetailService implements ITlThirdBillDetailService {

    private static final Logger logger = LoggerFactory.getLogger(TlThirdBillDetailService.class);

    @Resource
    private ExtTlBillTransCompareDetailMapper extTlBillTransCompareDetailMapper;
    @Resource
    private ExtTlThirdBillDetailMapper extTlThirdBillDetailMapper;

    @Override
    public TxnPage<TlThirdBillDetailRes> findAllPageByTenantId(Integer pageNum, Integer pageSize, String tenantId) throws TxnException {

        Page<TlThirdBillDetailRes> page = PageHelper.startPage(pageNum, pageSize, Constant.ORDER_BY_SORT);

        List<TlBillTransCompareDetail> detailList = extTlBillTransCompareDetailMapper.selectByCompareStatus(tenantId, Constant.COMPARE_FLAG_0);

        Assert.notEmpty(detailList, TxnRespCode.NO_DATA.getFormatUserTips());

        List<TlThirdBillDetailRes> res = BeanMapping.copyList(detailList, TlThirdBillDetailRes.class);
        return new TxnPage<>(pageNum, pageSize, page.getTotal(), res);

    }

    @Override
    public TlBillTransCompareDetail findById(String tenantId, String thirdChannel, Long id) {
        return extTlBillTransCompareDetailMapper.selectById(tenantId, thirdChannel, id);
    }

    @Override
    public TlThirdBillDetail findByThirdSeq(String tenantId, String thirdChannel, String seq, String type) {
        return extTlThirdBillDetailMapper.selectByThirdSeqAndType(seq, tenantId, thirdChannel, type);
    }

    @Override
    public void updateCompareStatus(String tenantId, String compareStatus, String desc, Long id) {
        extTlBillTransCompareDetailMapper.updateCompareStatusById(tenantId, compareStatus, desc, id);
    }


}
